//
//  String+Extension.swift
//  ParkManage
//
//  Created by cf on 2020/9/18.
//  Copyright © 2020 diligrp. All rights reserved.
//

import Foundation

extension String {
    
    /**
     用正则表达式判断字符窜是否符合规则
    */
    func isMatchWith(regExpression: String) -> Bool {
     
        let rules = NSPredicate(format: "SELF MATCHES %@", regExpression)
        let isMatch: Bool = rules.evaluate(with: self)
        return isMatch
    }
    
    /**
     计算字符串宽高
    */
    func sizeWithText(font: UIFont, size: CGSize) -> CGSize {
        let attributes = [NSAttributedString.Key.font: font]
        let option = NSStringDrawingOptions.usesLineFragmentOrigin
        let rect:CGRect = self.boundingRect(with: size, options: option, attributes: attributes, context: nil)
        return rect.size
    }
}
